package com.devilvan.grouping;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class CustomGroupingReducer extends Reducer<OrderBean, Text, Text,Text> {
    private Text result;

    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        result = new Text();
    }

    @Override
    protected void reduce(OrderBean key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        // 截取每组（根据订单号分组）价格排名前n的数据
        int i = 2;
        for (Text value : values) {
            if (i > 0) {
                result.set(value);
                context.write(new Text(key.getOrderId()),result);
                i--;
            } else break;
        }

    }
}
